package com.milk_shop.action;

import java.io.File;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.milk_shop.util.UploadUtil;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

@Component
@Scope("prototype")
public class UploadAction extends ActionSupport {
	private File upload;
	private String fileName;

	public File getUpload() {
		return upload;
	}

	public void setUpload(File upload) {
		this.upload = upload;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public String uploadFiles() {
		try {
			String url = UploadUtil.uploadFile(upload, fileName);
			ActionContext.getContext().put("imageUrl",url);
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println(e.getMessage());
			return ERROR;
		}
	}
}
